/*
 * Gate.h
 *
 *  Created on: 04.01.2011
 *      Author: 123
 */

#ifndef GATE_H_
#define GATE_H_
#include <oslib/oslib.h>
#include "Char.h"
extern int CameraX, CameraY;
struct gates {
	int x;
	int y;
	int earth;
	int newearth;
	//int *earth;
	//int *newearth;
	int newx;
	int nexy;

};
class sGates {
	gates LocalitionGates[100];
	int num;
	int triggeringgate;
	int i;

public:
	OSL_IMAGE *gate;
	sGates() {
		triggeringgate = -1;
	}
	void Draw() {
		for (i = 0; i < num; i++) {
			if (LocalitionGates[i].earth == Char[0].earth) {
				//itemtex[ItemGame[i].type]->centerX=16/2;
				//itemtex[ItemGame[i].type]->centerY=16/2;
				oslDrawImageXY(gate,LocalitionGates[i].x-CameraX,LocalitionGates[i].y-CameraY);
			}
		}
	}
	bool Create(int x, int y, int earth, int newearth, int newx) {
		LocalitionGates[num].x = x;
		LocalitionGates[num].y = y;
		LocalitionGates[num].earth = earth;
		LocalitionGates[num].newearth = newearth;
		LocalitionGates[num].newx = newx;
		num++;
		return 1;
	}
	bool Check() {
		for (i = 0; i < num; i++) {

			if ((LocalitionGates[i].x - Char[0].x < 10 && LocalitionGates[i].x
					- Char[0].x > -40) && (LocalitionGates[i].y - Char[0].y
					< -10 && LocalitionGates[i].y - Char[0].y > -60) &&
					LocalitionGates[i].earth == Char[0].earth) {
				triggeringgate = i;
				return true;
			}
		}
		return false;
	}
	int GetX() {
		return LocalitionGates[triggeringgate].newx;
	}
	int GetEarth() {
		return LocalitionGates[triggeringgate].newearth;
	}

};
extern sGates Gate;
#endif /* GATE_H_ */
